There is not much to consider when using tmap but two essential requirements:
Define your spatial object.
Choose a building block to determine how to display information.
# define and introduce every (new) # geospatial data objecttm_shape() +# choose at least one building block as # 'aesthetic layer'# for polygon layer choose from:tm_fill() +# polygons without borderstm_polygons() +# polygons with borderstm_borders() +# only borders of polygons# for line layer choose:tm_lines() +# for point layer choose:tm_dots() +tm_bubbles() +# for raster layer choosetm_raster() +tm_rgb() + ...# for all of them:?'tmap-element'
After we took care of our geometric types, we want to add some information to our data. The inner construction of each building block of tm_elements is the same.
Define the variable of interest first by stating the column name.
Add a name for the legend title and color palette, adjust the legend and scales …
tm_animate() allows you to create animated maps and visualize changes in spatial data, e.g. over time or attributes. You can customize the animation’s duration, frame rate, timeline sliders, and transition effects.
vote_gif <- attributes_cologne |> tidyr::pivot_longer(# Select all columns to pivotcols =c("cdu", "spd", "greens", "afd", "left", "fdp"), # New column name for party identifiernames_to ="party_id", # New column name for vote sharesvalues_to ="voteshare" ) |>tm_shape() +tm_polygons(c("voteshare")) +tm_facets_grid(pages ="party_id") tmap_animation( vote_gif, filename ="../img/vote_gif.gif",delay=150)
Save Maps
tmap offers support for various output formats, including:
Static Images: PNG, JPEG, TIFF, etc.
Interactive Web Maps: HTML, JavaScript (using packages like leaflet).
Animated Maps: GIF, MP4, etc.
You can also control width and height, dpi, etc.
# save regular maptmap_save(ecar_map, filename ="ecar_map.png")# save as interactive maptmap_save(ecar_map, filename ="ecar_map.html" )
Note On Mapping Responsible
In the best cases, maps are easy to understand and an excellent way to transport (scientific) messages.
In the worst cases, they simplify (spurious) correlations and draw a dramatic picture of the world.
Maps can shape narratives
Decisions on which projection you use (remember the true size projector?),
the segment of the world you choose,
and the colors and styles you add have a strong influence.